<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link href="../static/resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../static/resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../static/resources/css/style.css" rel="stylesheet">
    <link href="../static/resources/css/exam.css" rel="stylesheet">

    <script type="text/javascript" src="../static/resources/js/jquery/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../static/resources/vue/vue.js"></script>
    <script type="text/javascript" src="../static/resources/vue/date.js"></script>
    <script type="text/javascript" src="../static/resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../static/resources/js/all.js"></script>
    <script type="text/javascript" src="../static/resources/js/tag-list.js"></script>
    <script type="text/javascript" src="../static/resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../static/resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../static/resources/laypage/laypage.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/resources/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../static/resources/bootstrap/js/bootstrapValidator.min.js"></script>
    <link href="../static/resources/bootstrap/css/bootstrapValidator.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
    <form id="updFieldForm" style="width: 60%; ">
        <input type="hidden" name="fieldId" id="id" value="${data.fieldId}"/>
        <br />
        <div class="form-group">
            <label for="fieldName">所属题库：</label> <input type="text"
                                                 class="memo" id="fieldName" name="fieldName" placeholder="输入所属题库" value="${data.fieldName}">
        </div>
        <div class="form-group">&nbsp;
            <label for="memo"> 描 &nbsp; &nbsp;述&nbsp; ：</label> <input type="text"
                                                     class="form-control" id="memo" name="memo"
                                                     placeholder="输入描述" value="${data.memo}">
        </div>


        <div class="form-group">
            <button type="button" id="saveBtn" class="btn btn-success">提交</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
</body>
</html>
<script>
    var updateField = function() {

        $.ajax({
            type : 'POST',
            dataType : 'json',
            url : '/upField',
            data :/*{
                tagId:$("#tagId").val(),
                tagName:$("#tagName").val(),
                memp:$("#memo").val()
            },*/
                    $("#updFieldForm").serialize(),
            success : function() {
                $("#cancelBtn").click();
            }

        });

    };
    $("#saveBtn").click(function () {
        $("#updFieldForm").bootstrapValidator('validate');//提交验证
        if ($("#updFieldForm").data('bootstrapValidator').isValid()) {//获取验证结果，如果成功，执行下面代码
            updateField();
        }
    });


    $('#updFieldForm').bootstrapValidator({
        live: 'enabled',//验证时机，enabled是内容有变化就验证（默认），disabled和submitted是提交再验证
        excluded: [':disabled', ':hidden', ':not(:visible)'],//排除无需验证的控件，比如被禁用的或者被隐藏的
        submitButtons: '#saveBtn',//指定提交按钮，如果验证失败则变成disabled
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            fieldName: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入题库名'
                    },
                    stringLength: {//检测长度
                        min: 2,
                        max: 20,
                        message: '长度必须在2-20之间'
                    },

                }
            },
            memo: {
                validators: {
                    notEmpty: {//检测非空,radio也可用
                        message: '必须输入描述'
                    },
                    stringLength: {//检测长度

                        max: 50,
                        message: '长度必须小于50'
                    }

                }
            }
        }
    });


    $("#cancelBtn").click(function() {
        var index = parent.layer.getFrameIndex(window.name);
        parent.getFieldPageList();
        parent.layer.close(index);

    })


</script>